package guiLayer;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;

import net.miginfocom.swing.MigLayout;

public class MainFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final static String ORDERCARD = "ORDRER";
	private final static String OFFERCARD = "TILBUD";
	private final static String CUSTOMERCARD = "KUNDER";
	private final static String ITEMCARD = "VARER";
	private final static String EMPLOYEECARD = "MEDARBEJDERE";
	private final JPanel cardContainer;
	
	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainFrame frame = new MainFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MainFrame() {
		setTitle("Vestbjerg Byggecenter");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1000, 650);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		// Menu panel
		JPanel menuPanel = new JPanel();
		menuPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		contentPane.add(menuPanel, BorderLayout.WEST);
		
		// Order button
		JToggleButton tglbtnOrder = new JToggleButton(ORDERCARD);
		tglbtnOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CardLayout cl = (CardLayout)(cardContainer.getLayout());
				cl.show(cardContainer, ORDERCARD);
			}
		});
		ButtonGroup menuGroup = new ButtonGroup();
		menuGroup.add(tglbtnOrder);
		
		menuPanel.setLayout(new MigLayout("", "[120px]", "[50px][50px][50px][50px][50px]"));
		menuPanel.setLayout(new MigLayout("", "[120px]", "[50px][50px][50px][50px][50px]"));
		menuPanel.add(tglbtnOrder, "cell 0 0,grow");
		
		// Offer button
		JToggleButton tglbtnOffer = new JToggleButton(OFFERCARD);
		tglbtnOffer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CardLayout cl = (CardLayout)(cardContainer.getLayout());
				cl.show(cardContainer, OFFERCARD);
			}
		});
		menuGroup.add(tglbtnOffer);
		menuPanel.add(tglbtnOffer, "cell 0 1,grow");
		
		// Customer button
		JToggleButton tglbtnCustomer = new JToggleButton(CUSTOMERCARD);
		tglbtnCustomer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CardLayout cl = (CardLayout)(cardContainer.getLayout());
				cl.show(cardContainer, CUSTOMERCARD);
			}
		});
		menuGroup.add(tglbtnCustomer);
		menuPanel.add(tglbtnCustomer, "cell 0 2,grow");
		
		// Item button
		JToggleButton tglbtnItem = new JToggleButton(ITEMCARD);
		tglbtnItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				CardLayout cl = (CardLayout)(cardContainer.getLayout());
				cl.show(cardContainer, ITEMCARD);
			}
		});
		menuGroup.add(tglbtnItem);
		menuPanel.add(tglbtnItem, "cell 0 3,grow");
		
		// Employee button
		JToggleButton tglbtnEmployee = new JToggleButton(EMPLOYEECARD);
		tglbtnEmployee.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CardLayout cl = (CardLayout)(cardContainer.getLayout());
				cl.show(cardContainer, EMPLOYEECARD);
			}
		});
		menuGroup.add(tglbtnEmployee);
		menuPanel.add(tglbtnEmployee, "cell 0 4,grow");
		
		// Card container panel
		cardContainer = new JPanel();
		contentPane.add(cardContainer, BorderLayout.CENTER);
		cardContainer.setLayout(new CardLayout(0, 0));
		
		JPanel orderCard = new JPanel();
		cardContainer.add(orderCard, ORDERCARD);
		
		JPanel offerCard = new JPanel();
		cardContainer.add(offerCard, OFFERCARD);
		
		JPanel customerCard = new JPanel();
		cardContainer.add(customerCard, CUSTOMERCARD);
		
		JPanel itemCard = new ItemMainPanel();
		cardContainer.add(itemCard, ITEMCARD);
		
		JPanel employeeCard = new JPanel();
		cardContainer.add(employeeCard, EMPLOYEECARD);
	}

}
